|
|
|
|
|
|
|
Puzzle 21
What Is That Mapped Drive? Part 1 |
|
|
|
|
|
|
|
|
If you've used a Windows machine on a network, you know that it is possible to map network drives so that they appear as local drives on your system. This can be very important to you as a programmer. For example, you might not want to use a mapped network drive to save temporary files, or you might want to know the network provider for the mapped drive. The Win32 API makes it easy to find out which local drives are actually mapped network drives. Or does it? |
|
|
|
|
|
|
|
|
The Win32 API documentation defines the WNetGetConnection function as follows: |
|
|
|
|
|
|
|
|
DWORD WNetGetConnection( LPCTSTR lpLocalName, // pointer to local name
LPTSTR lpRemoteName, // pointer to buffer for remote name
LPDWORD lpnLength // pointer to buffer size, in characters
); |
|
|
|
|
|
|
|
|
It adds the following description for the lpnLength parameter: |
|
|
|
 |
|
 |
|
|
lpnLength |
|
|
|
 |
|
 |
|
|
Points to a variable that specifies the size, in characters, of the buffer pointed to by the lpRemoteName parameter If the function fails because the buffer is not big enough, this parameter returns the required buffer size. |
|
|
|
 |
|
 |
|
|
The return value of the function will be the constant ERROR_MORE_DATA if the buffer is not long enough to hold the data. |
|
|
|
|
|
|
|
|
The API declaration is fairly straightforward: |
|
|
|
|
|
|
|
|
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
lpszRemoteName As String, lpnLength As Long) As Long |
|
|
|
|
|
|
|
|
The Dynamic Link Library mpr.dll contains the network-independent API functionsthose network functions that will work regardless of the network or network provider you are using. The lpszLocalName parameter is declared ByVal |
|
|
|
|
|